package service

import (
	"time"
	"yybk/log"
	"yybk/model"
	"yybk/serializer"
)

type ResponderTeacherSubmit struct {
	CourseId  string `form:"course_id" json:"course_id" `
	TeacherId string `form:"teacher_id" json:"teacher_id" `
}

func (service ResponderTeacherSubmit) Insert() (model.Responder, *serializer.Response) {
	responder := model.Responder{
		CourseId:  service.CourseId,
		StartTime: time.Now(),
	}

	if err := model.DB.Create(&responder).Error; err != nil {
		return responder, &serializer.Response{
			Status: 500,
			Data:   err,
			Msg:    "responder插入错误",
			Error:  "DB ERROR",
		}
	}

	if err := log.SaveLog(service.TeacherId, service.CourseId, "responder"); err != nil {
		return responder, &serializer.Response{
			Status: 500,
			Data:   err,
			Msg:    "Log插入错误",
			Error:  "Log ERROR",
		}
	}
	return responder, nil
}
